/**
* Created by wl
* 项目管理>持有中-详情页-项目详情-对赌回购信息
*/
<template>
    <div class="ca-box ca-m-t-28 ca-p-20">
        <div v-if="!showEdit">
            <div class="ca-title">
                <h3>对赌回购</h3>
                <el-button type="text" class="ca-edit-btn el-icon-edit ca-m-r-10 edit-btn" @click="editInfo" :disabled="!isAuthIndexSee">编辑</el-button>
            </div>
            <table class="ca-table ca-m-t-15">
                <tr>
                    <th class="el-wid-15">触发时间</th>
                    <th class="el-wid-70">触发内容</th>
                    <th class="el-wid-15">处置方式</th>
                </tr>
                <tr v-for="(item, index) in gambling" :key="index" >
                    <td>
                        {{$moment(item.triggerTime).format('YYYY-MM-DD')}}
                    </td>
                    <td>
                        {{item.triggerNote}}
                    </td>
                    <td>
                        {{item.disposalMethods | getNameById('disposalMethods')}}
                    </td>
                </tr>
            </table>
            <table class="ca-table ca-m-t-15">
                <tr>
                    <th class="el-wid-15">触发时间</th>
                    <th class="el-wid-70">触发内容</th>
                    <th class="el-wid-15">处置方式</th>
                </tr>
                <tr v-for="(item, index) in buyBack" :key="index" >
                    <td>
                        {{$moment(item.triggerTime).format('YYYY-MM-DD')}}
                    </td>
                    <td>
                        {{item.triggerNote}}
                    </td>
                    <td>
                        {{item.disposalMethods | getNameById('disposalMethods')}}
                    </td>
                </tr>
            </table>
        </div>
        <csBettingBuyBack v-else :showBtn="true" @close="close" @save="save" :gambling="gambling" :buyBack="buyBack"></csBettingBuyBack>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '../../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { addRemind, isNoAuth } from '__service/utils';
    export default {
        data() {
            return {
                isAuthIndexSee: isNoAuth('持有中项目-项目详情-编辑'),
                showEdit: false,
                gambling: [], //对赌部分
                buyBack: [], //回购部分
            }
        },
        watch: {
        },
        props: {
        },
        mounted() {
            this.getInfo()
        },
        methods: {
            editInfo() {
                this.showEdit = true;
            },
            close() {
                this.showEdit = false;
            },
            async save() {
                this.showEdit = false
                await this.getInfo();
                // 添加小红点
                await addRemind({
                    dataId: this.$route.params.itemId, // 业务id
                    dataTab: 0, // tab页顺序 head 也为0 新建为'-1'
                    dataType: 2, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                });
                // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                this.$root.Dot.$emit('getDotList');
                // 添加小红点 end
            },
            getInfo() {
                this.gambling = []
                this.buyBack = []
                apiHttp(api.CHECK_PROTOCOL, {itemId: this.$route.params.itemId}).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        ret.data.itemHoldProtocolEntitys.map(item => {
                            if (item.protocolType === 1) { //对赌
                                this.gambling.push(item)
                            } else if (item.protocolType === 2) { //回购
                                this.buyBack.push(item)
                            }
                        })
                    }
                })
            },
        },
        components: {
            csBettingBuyBack: require('./edit'),
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.keyProtocol {
    border: 1px solid #ccc;
}
.edit-btn {
    float: right;
    cursor: pointer;
}
.ca-inner {
    display:table-cell;
    vertical-align:middle;
    background:#999999
}
.icon i {
    font-size: 20px;
    padding: 15px;
}
.el-wid-15 {
    width: 15%;
}
.el-wid-70 {
    width: 70%;
}
</style>